#ifndef   _FILECONF_H
#define   _FILECONF_H

#include "wx/defs.h"

#if wxUSE_CONFIG

#include "wx/textfile.h"
#include "wx/string.h"
#include "wx/confbase.h"

class wxFileConfigGroup;
class wxFileConfigEntry;
class wxFileConfigLineList;

#if wxUSE_STREAMS
class wxInputStream;
class wxOutputStream;
#endif // wxUSE_STREAMS

class wxFileConfig : public wxConfigBase {
  public:
    static wxString GetGlobalFileName( const wxChar *szFile );
    static wxString GetLocalFileName( const wxChar *szFile );

    wxFileConfig( const wxString& appName = wxEmptyString,
                  const wxString& vendorName = wxEmptyString,
                  const wxString& localFilename = wxEmptyString,
                  const wxString& globalFilename = wxEmptyString,
                  long style = wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_GLOBAL_FILE,
                  const wxMBConv& conv = wxConvAuto() );

    #if wxUSE_STREAMS
    // ctor that takes an input stream.
    wxFileConfig( wxInputStream &inStream, const wxMBConv& conv = wxConvAuto() );
    #endif // wxUSE_STREAMS

    // dtor will save unsaved data
    virtual ~wxFileConfig();
    void SetUmask( int mode ) { m_umask = mode; }
    virtual void SetPath( const wxString& strPath );
    virtual const wxString& GetPath() const { return m_strPath; }
    virtual bool GetFirstGroup( wxString& str, long& lIndex ) const;
    virtual bool GetNextGroup( wxString& str, long& lIndex ) const;
    virtual bool GetFirstEntry( wxString& str, long& lIndex ) const;
    virtual bool GetNextEntry( wxString& str, long& lIndex ) const;
    virtual size_t GetNumberOfEntries( bool bRecursive = false ) const;
    virtual size_t GetNumberOfGroups( bool bRecursive = false ) const;
    virtual bool HasGroup( const wxString& strName ) const;
    virtual bool HasEntry( const wxString& strName ) const;
    virtual bool Flush( bool bCurrentOnly = false );
    virtual bool RenameEntry( const wxString& oldName, const wxString& newName );
    virtual bool RenameGroup( const wxString& oldName, const wxString& newName );
    virtual bool DeleteEntry( const wxString& key, bool bGroupIfEmptyAlso = true );
    virtual bool DeleteGroup( const wxString& szKey );
    virtual bool DeleteAll();

    #if wxUSE_STREAMS
    virtual bool Save( wxOutputStream& os, const wxMBConv& conv = wxConvAuto() );
    #endif // wxUSE_STREAMS

  public:
    // functions to work with this list
    wxFileConfigLineList *LineListAppend( const wxString& str );
    wxFileConfigLineList *LineListInsert( const wxString& str,
                                          wxFileConfigLineList *pLine );   // NULL => Prepend()
    void      LineListRemove( wxFileConfigLineList *pLine );
    bool      LineListIsEmpty();

  protected:
    virtual bool DoReadString( const wxString& key, wxString *pStr ) const;
    virtual bool DoReadLong( const wxString& key, long *pl ) const;

    virtual bool DoWriteString( const wxString& key, const wxString& szValue );
    virtual bool DoWriteLong( const wxString& key, long lValue );

  private:
    static wxString GetGlobalDir();
    static wxString GetLocalDir();
    void Init();
    void CleanUp();
    void Parse( const wxTextBuffer& buffer, bool bLocal );
    void SetRootPath();
    bool DoSetPath( const wxString& strPath, bool createMissingComponents );
    void SetDirty() { m_isDirty = true; }
    void ResetDirty() { m_isDirty = false; }
    bool IsDirty() const { return m_isDirty; }
    wxFileConfigLineList *m_linesHead, *m_linesTail;

    wxString    m_strLocalFile,           // local  file name passed to ctor
                m_strGlobalFile;          // global
    wxString    m_strPath;                // current path (not '/' terminated)

    wxFileConfigGroup *m_pRootGroup, *m_pCurrentGroup;  // the current group

    wxMBConv    *m_conv;
    int m_umask;                          // the umask to use for file creation
    bool m_isDirty;                       // if true, we have unsaved changes

    DECLARE_NO_COPY_CLASS( wxFileConfig )
};

#endif
// wxUSE_CONFIG

#endif
//_FILECONF_H

